<#setting classic_compatible="true">
<style type="text/css">
.channeloptions .gou{
	display:none;
	width:20px;
	height:20px;
}
.channeloptions .y{
	background:url(/images/g.png) no-repeat center;
}
.channeloptions .edit{
	font-weight:bold;
}
.channeloptions input{
	width:100px;
}
.channeloptions .delete{
	display:inline-block;
	width:1em;
	height:1em;
	cursor:pointer;
}
.channeloptions p:hover .delete{
	background:url(/images/delete.png) no-repeat center;
}
.channeloptionadd {
}
.channeloptionadd label {
	margin: 0.5em 0px;
	display: block;
}
.channeloptionadd p{
	display:none;
	text-indent:0px;
}
.channeloptionadd p label{
	display:inline;
}
.channeloptionadd .button{
	text-align:center;
}
.channeloptionlistedit{
	display:none;
}
</style>
<script type="text/javascript">
$(document).ready(function(e) {
	dialog('.channeloptionadd',{
		autoOpen:false,
		modal:true,
		resizable:false,
		title:'添加模块选项',
		width:400
	});
	dialog('.channeloptionlistedit',{
		autoOpen:false,
		modal:true,
		resizable:false,
		title:'列表显示选项编辑',
		width:400
	});
	if(channeltype=='list'){
		$('.channeloptions .gou').css('display','inline-block');
		$('.channeloptionadd p').show();
	}
	$('.channeloptions .type').each(function(index, element) {
        switch($(this).text()){
		case 'text':$(this).text('单行文本');break;
		case 'textarea':$(this).text('多行文本');break;
		case 'miniEditor':$(this).text('迷你编辑');break;
		case 'simpleEditor':$(this).text('简单编辑');break;
		case 'fullEditor':$(this).text('高级编辑');break;
		case 'file':$(this).text('文件');break;
		case 'image':$(this).text('图片');break;
		}
    });
	$('.channeloptions .edit').click(function(e){
		input_edit(this,'system/channelOption!save.action');
	});
});
function channeloptionadd(){
	if(checkForm($('.channeloptionadd *[name]'))){
		$.ajax({
			url:'system/channelOption!addAction.action',
			type:'POST',
			data:serializeArray($('.channeloptionadd *[name]')),
			dataType:"JSON",
			success: function(rs){
				if(rs.code=='0'){
					$('.channeloptionadd').dialog('close');
					goPage('system/channelOption.action?channelid='+'${channelid}','.channeloption');
				}else{
					alert(rs.msg);
				}
			}
		});
	}
}
function showchanneloptionadd(){
	$('.channeloptionadd').dialog('open');
}
function channeloptiondelete(_this,id){
	if(!confirm('确定删除此模块选项吗？')){
		return;
	}
	$.getJSON('system/channelOption!delete.action',{id:id},function(rs){
		if(rs.code=='1'){
			goPage('system/channel!detail.action?id=${channelid}','#main')
		}else{
			alert(rs.msg);
		}
	});
}
function channeloptionlistchange(_this){
	var data={
		id:$(_this).val(),
		update_name:'list',
		update_value:$(_this).is(':checked')?1:0
	};
	$.ajax({
			url:'system/channelOption!save.action',
			type:'POST',
			data:data,
			dataType:"JSON",
			success: function(rs){
				var span=$('<span>'+rs.msg+'</span>');
				$(_this).parent().append(span);
				$(span).delay(1000).fadeOut(function(){$(this).remove();});
				if(rs.code=='1'){
					$(span).addClass('ok')
					$(".channeloptionlistedit").on("dialogclose",function(event,ui){fleshPage();});
				}else{
					$(span).addClass('error')
					$(_this).attr('checked',!$(_this).is(':checked'));
				}
			}
		});
}
</script>
<div class="channeloptions">
  <p>
    <button type="button" onClick="$('.channeloptionlistedit').dialog('open')">编辑列表显示内容</button>
  </p>
  <#list rslist as mo>
  <p><span class="gou<#if mo.list == "1" > y</#if>"></span><span>${mo.name}</span>：<span type="text" class="edit" id="${mo._id}" name="description" regx="${check.description}">${mo.description}</span>：<span class="type">${mo.type}</span><span class="delete" onClick="channeloptiondelete(this,'${mo._id}')"></span></p>
  </#list>
  <p>
    <button type="button" onClick="showchanneloptionadd()">添加</button>
  </p>
</div>
<div class="channeloptionadd">
  <input type="hidden" name="channelid" value="${channelid}" />
  <label>名称：
    <input type="text" name="name" regx="${check.name}" />
  </label>
  <label>描述：
    <input type="text" name="description" regx="${check.description}" />
  </label>
  <label>排序：
    <input type="number" name="index" regx="${check.index}" />
  </label>
  <label>类型：
    <select name="type">
      <option value="text">单行文本</option>
      <option value="textarea">多行文本</option>
      <option value="miniEditor">简单编辑</option>
      <option value="simpleEditor">迷你编辑</option>
      <option value="fullEditor">高级编辑</option>
      <option value="file">文件</option>
      <option value="image">图片</option>
    </select>
  </label>
  <p>列表显示：
    <label>
      <input type="radio" name="list" value="0" checked>
      否</label>
    &nbsp;&nbsp;
    <label>
      <input type="radio" name="list" value="1">
      是</label>
  </p>
  <div class="button">
    <button type="button" onClick="channeloptionadd()">添加</button>
    <button type="button" onClick="$('.channeloptionadd').dialog('close');">取消</button>
  </div>
</div>
<div class="channeloptionlistedit"> <#list rslist as mo>
<p><input type="checkbox" value="${mo._id}" onChange="channeloptionlistchange(this)" <#if mo.list=="1">checked</#if> /><span>${mo.name}</span>：<span>${mo.description}</span>：<span class="type">${mo.type}</span></p>
</#list> </div>
